<template>
    <section class="chart-container">
        <el-row>
            <el-col :span="12">
                <div id="chartColumn" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="12">
                <div id="chartBar" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="12">
                <div id="chartLine" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="12">
                <div id="chartPie" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="24">
                <a href="http://echarts.baidu.com/examples.html" target="_blank" style="float: right;">more>></a>
            </el-col>
        </el-row>
    </section>
</template>

<script>
    import echarts from 'echarts'

    export default {
        data() {
            return {
                chartColumn: null,
                chartBar: null,
                chartLine: null,
                chartPie: null,

                clueResource:[],
                cluexAxis:[],
                clueyAxis:[],
              DepositSales:[],

              DepositSalesxAxis:[],//时间
              DepositSalesyAxisSalesCount:[],
              DepositSalesyAxisSalesSum:[]


            }
        },

        methods: {

          //获定金销售记录
          getDepositSales(){
            this.$http.get("/deposit/getDepositSales",this.businessForm)
                .then(result=>{
                  result = result.data
                  if (result.success){
                    this.DepositSales=  result.resultObj
                    console.log(this.DepositSales)

                    for (let i = 0; i < this.DepositSales.length; i++) {
                      this.DepositSalesxAxis.push(this.DepositSales[i].date)
                      this.DepositSalesyAxisSalesSum.push(this.DepositSales[i].salesSum)
                      this.DepositSalesyAxisSalesCount.push(this.DepositSales[i].salesCount)
                    }
                    console.log("------------")

                    console.log(this.DepositSalesxAxis)
                    console.log(this.DepositSalesyAxisSalesSum)
                    console.log(this.DepositSalesyAxisSalesCount)
                  this. drawLineChart()
                  }else{
                  }
                })
                .catch(result=>{
                })
          },



          //获取线索来源
          getClueResource(){
            this.$http.get("/clue/getClueResource",this.businessForm)
                .then(result=>{
                  result = result.data

                  if (result.success){
                     this.clueResource=  result.resultObj
                    // console.log(this.clueResource)
                    // var listx[]
                    // var listy[]
                    for (let i = 0; i < this.clueResource.length; i++) {
                      this.cluexAxis.push(this.clueResource[i].name.toString())
                      this.clueyAxis.push(this.clueResource[i].value)
                    }
                    // console.log("------------")
                    // console.log("cluexAxis"+this.cluexAxis)
                    // console.log("cluexAxistype"+this.cluexAxis.type)
                    // console.log("clueyAxis"+this.clueyAxis)
                    this.drawColumnChart()
                  }else{
                  }
                })
                .catch(result=>{
                })
          },


            drawColumnChart() {
                this.chartColumn = echarts.init(document.getElementById('chartColumn'));
                this.chartColumn.setOption({
                  title: { text: '线索来源' },
                  tooltip: {},
                  xAxis: {
                      data: this.cluexAxis
                  },
                  yAxis: {},
                  series: [{
                      name: '人数',
                      type: 'bar',
                      data: this.clueyAxis
                    }]
                });
            },
            drawBarChart() {
                this.chartBar = echarts.init(document.getElementById('chartBar'));
                this.chartBar.setOption({
                    title: {
                        text: 'Bar Chart',
                        subtext: '数据来自网络'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow'
                        }
                    },
                    legend: {
                        data: ['2011年', '2012年']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01]
                    },
                    yAxis: {
                        type: 'category',
                        data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)']
                    },
                    series: [
                        {
                            name: '2011年',
                            type: 'bar',
                            data: [18203, 23489, 29034, 104970, 131744, 630230]
                        },
                        {
                            name: '2012年',
                            type: 'bar',
                            data: [19325, 23438, 31000, 121594, 134141, 681807]
                        }
                    ]
                });
            },
            drawLineChart() {
                this.chartLine = echarts.init(document.getElementById('chartLine'));
                this.chartLine.setOption({
                    title: {
                        text: '统计定金金额和定金笔数'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['订单数', '成交金额']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: this.DepositSalesxAxis
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '销售分数',
                            type: 'line',
                            stack: '总量',
                            data: this.DepositSalesyAxisSalesCount
                        },
                        {
                            name: '售出金额',
                            type: 'line',
                            stack: '总量',
                            data: this.DepositSalesyAxisSalesSum
                        },
                    ]
                });
            },
            drawPieChart() {
                this.chartPie = echarts.init(document.getElementById('chartPie'));
                this.chartPie.setOption({
                    title: {
                        text: 'Pie Chart',
                        subtext: '纯属虚构',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
                    },
                    series: [
                        {
                            name: '访问来源',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            data: [
                                { value: 335, name: '直接访问' },
                                { value: 310, name: '邮件营销' },
                                { value: 234, name: '联盟广告' },
                                { value: 135, name: '视频广告' },
                                { value: 1548, name: '搜索引擎' }
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
            },
            drawCharts() {
                this.drawColumnChart()
                this.drawBarChart()
                this.drawLineChart()
                this.drawPieChart()
            },
        },

        mounted: function () {
            this.drawCharts()
          this.getClueResource()
          this.getDepositSales()
        },
        updated: function () {
            this.drawCharts()

        }
    }
</script>

<style scoped>
    .chart-container {
        width: 100%;
        float: left;
    }
    /*.chart div {
        height: 400px;
        float: left;
    }*/

    .el-col {
        padding: 30px 20px;
    }
</style>
